package com.huawei.updatesdk.service.c;

import android.content.Context;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import com.huawei.hms.common.data.DataBufferSafeParcelable;
import com.huawei.updatesdk.a.b.a.a;
import java.io.File;
import java.lang.reflect.Method;

public class h {
    private static String[] a = null;

    public static String[] a() {
        if (a == null) {
            a = a(a.a().b());
        }
        return (String[]) a.clone();
    }

    private static String[] a(Context context) {
        String b = b(context);
        return new String[]{b + File.separator + "Android" + File.separator + DataBufferSafeParcelable.DATA_FIELD + File.separator + context.getPackageName() + File.separator + "files"};
    }

    private static String b(Context context) {
        StorageVolume[] storageVolumeArr;
        String str;
        StorageManager storageManager = (StorageManager) context.getSystemService("storage");
        StorageVolume[] storageVolumeArr2 = new StorageVolume[0];
        try {
            Method method = StorageManager.class.getMethod("getVolumeList", new Class[0]);
            method.setAccessible(true);
            storageVolumeArr = (StorageVolume[]) method.invoke(storageManager, new Object[0]);
        } catch (Throwable e) {
            com.huawei.updatesdk.a.a.b.a.a.a.a("StorageManage", "can not find method:getVolumeList", e);
            storageVolumeArr = storageVolumeArr2;
        } catch (Throwable e2) {
            com.huawei.updatesdk.a.a.b.a.a.a.a("StorageManage", "can not find method:getVolumeList", e2);
            storageVolumeArr = storageVolumeArr2;
        } catch (Throwable e22) {
            com.huawei.updatesdk.a.a.b.a.a.a.a("StorageManage", "can not find method:getVolumeList", e22);
            storageVolumeArr = storageVolumeArr2;
        }
        if (storageVolumeArr != null && storageVolumeArr.length > 0) {
            Method b = b();
            Method c = c();
            for (Object obj : storageVolumeArr) {
                boolean booleanValue;
                String str2;
                if (b != null) {
                    try {
                        booleanValue = ((Boolean) b.invoke(obj, new Object[0])).booleanValue();
                    } catch (Throwable e222) {
                        com.huawei.updatesdk.a.a.b.a.a.a.a("StorageManage", "can not invoke method:getVolumeList", e222);
                        booleanValue = false;
                    } catch (Throwable e2222) {
                        com.huawei.updatesdk.a.a.b.a.a.a.a("StorageManage", "can not invoke method:getVolumeList", e2222);
                    }
                    str = "";
                    str2 = (String) c.invoke(obj, new Object[0]);
                    if (booleanValue && !str2.contains("usb")) {
                        return str2;
                    }
                }
                booleanValue = false;
                str = "";
                try {
                    str2 = (String) c.invoke(obj, new Object[0]);
                } catch (Throwable e22222) {
                    com.huawei.updatesdk.a.a.b.a.a.a.a("StorageManage", "can not invoke method:getPath", e22222);
                    str2 = str;
                } catch (Throwable e222222) {
                    com.huawei.updatesdk.a.a.b.a.a.a.a("StorageManage", "can not invoke method:getPath", e222222);
                    str2 = str;
                }
                if (booleanValue) {
                }
            }
        }
        return null;
    }

    private static Method b() {
        Method method;
        Throwable e;
        try {
            method = StorageVolume.class.getMethod("isRemovable", new Class[0]);
            try {
                method.setAccessible(true);
            } catch (Exception e2) {
                e = e2;
                com.huawei.updatesdk.a.a.b.a.a.a.a("StorageManage", "can not find method:isRemovable", e);
                return method;
            }
        } catch (Throwable e3) {
            Throwable th = e3;
            method = null;
            e = th;
            com.huawei.updatesdk.a.a.b.a.a.a.a("StorageManage", "can not find method:isRemovable", e);
            return method;
        }
        return method;
    }

    private static Method c() {
        Method method;
        Throwable e;
        try {
            method = StorageVolume.class.getMethod("getPath", new Class[0]);
            try {
                method.setAccessible(true);
            } catch (Exception e2) {
                e = e2;
                com.huawei.updatesdk.a.a.b.a.a.a.a("StorageManage", "can not find method:getPath", e);
                return method;
            }
        } catch (Throwable e3) {
            Throwable th = e3;
            method = null;
            e = th;
            com.huawei.updatesdk.a.a.b.a.a.a.a("StorageManage", "can not find method:getPath", e);
            return method;
        }
        return method;
    }
}
